package com.binjiang.pengfuhao.控制;


import com.binjiang.pengfuhao.pojo.文件对象;
import com.binjiang.pengfuhao.服务对象.接收切片;

import fr.opensagres.poi.xwpf.converter.xhtml.XHTMLConverter;
import fr.opensagres.poi.xwpf.converter.xhtml.XHTMLOptions;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.StringWriter;

@RestController
public class 接受前端请求 {

    @Autowired
    private 接收切片 接收切片;


    @PostMapping("/上传文件")
public String 接收上传文件(文件对象 file) throws IOException {




    return   接收切片.单片写入(file);

}




    @PostMapping("/返回文件")
    public String 返回文件() throws IOException {

        File file = new File("E:\\测试\\云盘\\src\\main\\resources\\templates\\毕业后 我要去.docx");
        FileInputStream fileInputStream= new FileInputStream(file);
        XWPFDocument re = new XWPFDocument(fileInputStream);
        StringWriter stringWriter = new StringWriter();

        XHTMLConverter xhtmlConverter = (XHTMLConverter) XHTMLConverter.getInstance();
        XHTMLOptions options = XHTMLOptions.getDefault();
        xhtmlConverter.convert(re,  stringWriter,options);
        String html = new String (stringWriter.toString().getBytes("utf-8"),"utf-8");


        System.out.println(html);
        re.close();


        return  html;

    }


}
